package com.sx.controller;

import com.sx.service.SupplierService;
import com.sx.service.serviceImpl.SupplierServiceImpl;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;

import java.io.Serial;

@WebServlet("/checkSupplierIdExists.action")

public class checkedSupplierId extends HttpServlet {
    @Serial
    private static final long serialVersionUID = 1L;
    private final SupplierService supplierService = new SupplierServiceImpl();

    /**
     * 处理客户端的请求，检查给定的ID是否存在于系统中
     *
     * @param req HTTP请求对象，用于获取请求参数中的ID
     * @param res HTTP响应对象，用于向客户端发送ID存在性的结果
     * @throws jakarta.servlet.ServletException 如果在执行过程中遇到Servlet异常
     * @throws java.io.IOException              如果在执行过程中遇到I/O异常
     */
    public void service(jakarta.servlet.http.HttpServletRequest req, jakarta.servlet.http.HttpServletResponse res) throws jakarta.servlet.ServletException, java.io.IOException {
        // 从请求参数中获取ID
        String id = req.getParameter("id");
        // 调用业务服务方法，检查ID是否存在
        boolean flag = supplierService.checkIdExists(id);
        // 将检查结果转换为字符串并发送给客户端
        res.getWriter().write(String.valueOf(flag));
    }
}
